#include <iostream>
#include "./contacts.pb.h" // 引入编译生成的头文件
using namespace std;

int main()
{
    string people_str;
    // 序列化
    {
        //设置创建一个结构化对象
        contacts::PeopleInfo people;
        people.set_age(20);
        people.set_name("张三");
        // 调用序列化方法，将序列化后的二进制序列存入 string 中
        if (!people.SerializeToString(&people_str)) 
        {
            cout << "序列化联系人失败." << endl;
        }
        // 打印序列化结果
        cout << "序列化成功，结果： " << people_str.size() << endl;
    }

    cout << endl;

    // 反序列化
    {
        contacts::PeopleInfo people;
        // 调用反序列化方法，读取 string 中存放的二进制序列，并反序列化出对象
        if (!people.ParseFromString(people_str)) {
        cout << "反序列化出联系人失败." << endl;
        }
        // 打印结果
        cout << "反序列化成功" << endl;
        cout << "Parse age: " << people.age() << endl;
        cout << "Parse name: " << people.name() << endl;
    }
    return 0;
}


typedef std::shared_ptr<TcpConnection> TcpConnectionPtr;
typedef std::function<void (const TcpConnectionPtr&)> ConnectionCallback;
typedef std::function<void (const TcpConnectionPtr&, Buffer*, Timestamp)> MessageCallback;

class InetAddress : public muduo::copyable
{
public:
    InetAddress(StringArg ip, uint16_t port, bool ipv6 = false);
};

class TcpServer : noncopyable
{
    public:
    enum Option
    {
        kNoReusePort,    
        kReusePort,
    };

    TcpServer(EventLoop* loop,
        const InetAddress& listenAddr,
        const string& nameArg,
        Option option = kNoReusePort);

    void setThreadNum(int numThreads);

    void start();
    /// 当一个新连接建立成功的时候被调用

    void setConnectionCallback(const ConnectionCallback& cb)
    { connectionCallback_ = cb; }

    /// 消息的业务处理回调函数---这是收到新连接消息的时候被调用的函数
    void setMessageCallback(const MessageCallback& cb)
    { messageCallback_ = cb; }
};